﻿using System;
using System.Web;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using Castle.MonoRail.Framework;
using Castle.MonoRail.Framework.Internal;

using eduSrc.Models;
using eduSrc.Services;
using Discuz.Common;
using Discuz.Forum;
using Discuz.Entity;
using Discuz.Data;
using Discuz.Config;

namespace eduSrc.Web.Code.Components
{
    public class Header : ViewComponent
    {
        /*
        public override void Render()
        {
            Context.ContextVars["it"] = "GSpring";
            Context.RenderBody();
        }
        */

        public override void Render()
        {
            try
            {
                // 获取常规配置
                GeneralConfigInfo config = GeneralConfigs.GetConfig();
                // 刷新当前用户身份信息，返回到oluserinfo中
                OnlineUserInfo oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
                // 现在oluserinfo中就有当前用户的身份信息了
                // 例如oluserinfo.Username是用户名，oluserinfo.Userid是用户id序号，oluserinfo.Groupid是用户组序号。
                // 如果当前用户是游客，则oluserinfo.Userid为-1。

                if (oluserinfo.Userid > 0)
                {
                    PropertyBag["username"] = oluserinfo.Username;
                    PropertyBag["userid"] = oluserinfo.Userid;
                }
            }
            catch(Exception ex)
            {
                eduSrcLog4net.logError(ex.Message);  
                PropertyBag["errorInfo"] = ex.Message;
            }
            finally
            {
                RenderView("default"); 
                //base.Render();
            }
        }
    }
}
